package net.flyinggroup.introduction;

import io.rsocket.Payload;
import io.rsocket.RSocket;
import io.rsocket.core.RSocketConnector;
import io.rsocket.transport.netty.client.TcpClientTransport;
import io.rsocket.util.DefaultPayload;

import static net.flyinggroup.introduction.Constants.TCP_PORT;

public class ReqResClient {
    private final RSocket socket;

    public ReqResClient() {
        this.socket = RSocketConnector.connectWith(TcpClientTransport.create(TCP_PORT)).block();
    }

    public String callBlocking(String info) {
        return socket.requestResponse(DefaultPayload.create(info))
                .map(Payload::getDataUtf8)
                .block();
    }

    public void dispose() {
        socket.dispose();
    }
}
